﻿#include "checkin.h"

#include "../../include/itframework.h"
#include "../../include/itlogger.h"
#include "../../include/itservice.h"
#include "../../include/itcommon.h"

#include "../../Public/Facer/define.h"

extern "C" __declspec(dllexport) ITModelBase* GetInstance(ITFramework *pFrame)
{
    CheckIn *pCheckIn = CheckIn::GetInstance();
    pCheckIn->SetFramework(pFrame);
    return dynamic_cast<ITModelBase*>(pCheckIn);
}

void CheckIn::SetFramework(ITFramework *pFrm)
{
    m_pFramework = pFrm;
    m_pFramework->GetLogger(&m_pLogger);
    m_pFramework->GetCommon(&m_pcommon);
}

CheckIn::CheckIn()
{
    qDebug() << "CheckIn::CheckIn()";
}

CheckIn::~CheckIn()
{
    qDebug() << "CheckIn::~CheckIn()";
}

T_BEGIN_MAP(CheckIn)
    T_HANDLER(UI_CHECKIN_request_CMD_ID,OnSend,TUICheckIn_request_Param,TUICheckIn_reply_Param)
    T_HANDLER(UI_CHECKIN_reply_CMD_ID,OnSendReply,TUICheckIn_reply_Param,TObject)
T_END_MAP

void CheckIn::OnSend(TUICheckIn_request_Param *pInArgs, TUICheckIn_reply_Param *pOutArgs)
{
    qDebug() << "CheckIn::OnSend InArg=" << pInArgs->send << "thread id=" << QThread::currentThreadId();
    QThread::sleep(20);
    QString szReply = QString("recv %1. reply: hello I'm CheckIn OnSend").arg(pInArgs->send);
    if(NULL != pOutArgs)
        m_pcommon->copystru8(szReply.toUtf8().data(), pOutArgs->sendReply, sizeof(pOutArgs->sendReply));
}

void CheckIn::OnSendReply(TUICheckIn_reply_Param *pInArgs, TObject *pOutArgs)
{
    qDebug() << "CheckIn::OnSendReply=" << pInArgs->sendReply << "thread id=" << QThread::currentThreadId();
    return;
    pfnCBClient pfn = NULL; void *userdata = NULL;
    m_pFramework->GetCBCheckIn(&pfn, (void**)&userdata);
    Tai_CB_Msg msg;
    TUICheckIn_test param;
    param.text = "test QString send!";
    param.nResult = 1;
    msg.ulMsg = UI_CheckIn_cb_test;
    msg.lParam = (int)&param;
    pfn(&msg,userdata);
    m_pFramework->GetCBPropagandist(&pfn, (void**)&userdata);
    msg.ulMsg = 4444;
    pfn(&msg,userdata);
}
